package com.mobartisan.workinglunch.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mobartisan.workinglunch.R;
import com.mobartisan.workinglunch.bean.AccountRecord;
import com.mobartisan.workinglunch.ui.activity.ChangeActivity;
import com.mobartisan.workinglunch.ui.viewholder.HistoryViewHolder;

import java.util.List;

/**
 * Created by L on 2017/4/27.
 */

public class HistoryAdapter extends RecyclerView.Adapter<HistoryViewHolder> {
    List<AccountRecord> list;
    Context context;

    public HistoryAdapter(List<AccountRecord> list) {
        this.list = list;
    }

    @Override
    public HistoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_history,parent,false);
        HistoryViewHolder historyViewHolder = new HistoryViewHolder(view);
        return historyViewHolder;
    }

    @Override
    public void onBindViewHolder(HistoryViewHolder holder, int position) {
        holder.date.setText("日期:"+list.get(position).getDateStamp());
        holder.time.setText("时间:"+list.get(position).getTimeStamp());
        int i =list.get(position).getType();
        String type = "";
        switch (i){
            case 0:
                type = "早上";
                break;
            case 1:
                type = "中午";
                break;
            case 2:
                type = "晚上";
                break;
            case 3:
                type = "其它";
                break;
        }
        holder.type.setText("类型:"+type);
        holder.money.setText("金额:"+list.get(position).getMoney().toString());
        holder.amend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ChangeActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("dateStamp",list.get(position).getDateStamp());
                bundle.putString("timeStamp",list.get(position).getTimeStamp());
                bundle.putInt("type", list.get(position).getType());
                bundle.putString("money",list.get(position).getMoney().toString());
                bundle.putString("objectId",list.get(position).getObjectId());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
